package com.aispeech.asr.apis.detection;

import java.io.IOException;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.web.reactive.config.EnableWebFlux;

import com.aispeech.asr.clib.arpc.ARpc;
import com.aispeech.asr.clib.decoder.AudioDecoder;
import com.aispeech.asr.clib.vad.Vad;
import com.aispeech.jarpc.JArpc;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@SpringBootApplication(exclude = MongoAutoConfiguration.class)
@ComponentScan("com.aispeech.asr")
@EnableWebFlux
public class EventDetectionApp implements CommandLineRunner, ApplicationListener<ContextClosedEvent> {

    public static void main(String[] args) {
        System.setProperty("java.net.preferIPv4Addresses", "true"); //解决Netty DNS解析的时候，会使用AAAA记录，换取IPv6的地址
        System.setProperty("java.net.preferIPv4Stack", "true"); //解决Netty DNS解析的时候，会使用AAAA记录，换取IPv6的地址

        SpringApplication.run(EventDetectionApp.class, args);
    }

    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
        if (contextClosedEvent.getApplicationContext().getParent() == null) {
            log.info("EventDetectionApp shutdown...");
            //ARpc.destroy();
        }
    }

    @Override
    public void run(String... args) {
    	try {
			JArpc.initialize();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.info("SscApp JArpc failed,...", e);
		}
        log.info("EventDetectionApp Version: {}, running on: {}", "", System.getenv("ENV"));
    }
    
    
    
}
